// 版权归 瞄你个汪 所有。使用本代码应遵守相关法律法规和Apache 2.0开源许可要求。
package top.geeke.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.ibatis.type.JdbcType;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.security.core.userdetails.UserDetails;
import top.geeke.entity.base.EntityBaseData;
import top.geeke.eunm.SysAccountTypeEnum;
import top.geeke.eunm.SysCultureLevelEnum;
import top.geeke.eunm.SysGenderEnum;
import top.geeke.eunm.SysStatusEnum;
import top.geeke.toolkit.supertable.annotation.SuperColumn;
import top.geeke.toolkit.supertable.annotation.SuperIndex;
import top.geeke.toolkit.supertable.annotation.SuperTable;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 系统用户表
 * </p>
 * @author 瞄你个汪
 * @since 2024-05-01 12:00:00
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName(value = "sys_user")
@SuperTable(value = "系统用户表", isSystem = true, indexes = {
        @SuperIndex(indexName ="sys_index_{table}_A", indexFields ="account"),
        @SuperIndex(indexName ="sys_index_{table}_M", indexFields ="mobile"),
})
public class SysUser extends EntityBaseData /* implements UserDetails */ {
    private static final long serialVersionUID = 1L;

    @SuperColumn(value = "账号", length = 64)
    private String account;

    @JsonIgnore
    @JsonIgnoreProperties
    @SuperColumn(value = "密码", length = 512)
    private String password;

    @SuperColumn(value = "手机号", length = 16)
    private String mobile;

    @SuperColumn(value = "真实姓名", length = 32)
    private String realName;

    @SuperColumn(value = "性别")
    private SysGenderEnum sex = SysGenderEnum.Other;

    @SuperColumn(value = "年龄", nullable = true)
    private Integer age;

    @SuperColumn(value = "生日", nullable = true)
    @TableField(jdbcType = JdbcType.DATE)
    private LocalDate birthday;

    @SuperColumn(value = "昵称", nullable = true, length = 32)
    private String nickName;

    @SuperColumn(value = "头像", nullable = true, length = 512)
    private String avatar;

    @SuperColumn(value = "民族", nullable = true, length = 32)
    private String nation;

    @SuperColumn(value = "籍贯", nullable = true, length = 64)
    private String origin;

    @SuperColumn(value = "证件号码", nullable = true, length = 32)
    private String idCardNum;

    @SuperColumn(value = "邮箱", nullable = true, length = 64)
    private String email;

    @SuperColumn(value = "地址", nullable = true, length = 64)
    private String address;

    @SuperColumn(value = "文化程度", defaultValue = "0")
    private SysCultureLevelEnum cultureLevel = SysCultureLevelEnum.Level0;

    @SuperColumn(value = "政治面貌", nullable = true, length = 16)
    private String politicalOutlook;

    @SuperColumn(value = "毕业院校", nullable = true, length = 128)
    private String college;

    @SuperColumn(value = "办公电话", nullable = true, length = 16)
    private String officePhone;

    @SuperColumn(value = "紧急联系人", nullable = true, length = 32)
    private String emergencyContact;

    @SuperColumn(value = "紧急联系人电话", nullable = true, length = 16)
    private String emergencyPhone;

    @SuperColumn(value = "紧急联系人地址", nullable = true, length = 256)
    private String emergencyAddress;

    @SuperColumn(value = "个人简介", nullable = true, length = 512)
    private String introduction;

    @SuperColumn(value = "账号类型")
    private SysAccountTypeEnum accountType = SysAccountTypeEnum.Guest;

    @SuperColumn(value = "工号", nullable = true, length = 32)
    private String jobNum;

    @SuperColumn(value = "职级", nullable = true, length = 32)
    private String posLevel;

    @SuperColumn(value = "职称", nullable = true, length = 32)
    private String posTitle;

    @SuperColumn(value = "擅长领域", nullable = true, length = 32)
    private String expertise;

    @SuperColumn(value = "办公区域", nullable = true, length = 32)
    private String officeZone;

    @SuperColumn(value = "办公室", nullable = true, length = 32)
    private String office;

    @SuperColumn(value = "入职日期", nullable = true)
    private LocalDate joinDate;

    @SuperColumn(value = "最后登录IP", nullable = true)
    private String lastLoginIp;

    @SuperColumn(value = "最后登录时间", nullable = true)
    private LocalDateTime lastLoginTime;

    @SuperColumn(value = "最后登录地址", nullable = true, length = 128)
    private String lastLoginAddress;

    @SuperColumn(value = "最后登录设备", nullable = true, length = 128)
    private String lastLoginDevice;

    @SuperColumn(value = "登录次数", nullable = true)
    private int loginCount;

    @SuperColumn(value = "账号锁标记", defaultValue = "0")
    private boolean isLocked;

    @SuperColumn(value = "账号是否过期", defaultValue = "0")
    private boolean isExpired;

    @SuperColumn(value = "状态")
    private SysStatusEnum status = SysStatusEnum.Enabled;

    @SuperColumn(value = "排序", defaultValue = "100")
    private Integer orderNo = 100;

    @SuperColumn(value = "备注", nullable = true, length = 128)
    private String remark;

    @JsonIgnore
    @JsonIgnoreProperties
    @TableField(exist = false)
    private SysOrg org;

    @JsonIgnore
    @JsonIgnoreProperties
    @TableField(exist = false)
    private SysTenant tenant;

    @JsonIgnore
    @JsonIgnoreProperties
    @TableField(exist = false)
    private List<SysRole> roles;

    @JsonIgnore
    @JsonIgnoreProperties
    @TableField(exist = false)
    private List<SysMenu> permissionList;

//    @Override
//    public Collection<? extends GrantedAuthority> getAuthorities() {
//        return permissionList;
//    }
//
//    @Override
//    public String getUsername() {
//        return account;
//    }
//
//    @Override
//    public boolean isAccountNonExpired() {
//        return !isExpired;
//    }
//
//    @Override
//    public boolean isAccountNonLocked() {
//        return !isLocked;
//    }
//
//    @Override
//    public boolean isCredentialsNonExpired() {
//        return !isExpired;
//    }
//
//    @Override
//    public boolean isEnabled() {
//        return getStatus() == SysStatusEnum.Enabled;
//    }
}
